<?php
namespace app\oa\ext;
use \app\common\model\UserStatus as Status;
class UserStatus {
    const SESSION_PREFIX = 'onepeter_oa_';
    const SESSION_ROLE = 'role';
    const SESSION_DEPARTMENT_ID = 'department_id';

    public static function login($id, $username, $role, $departmentId) {
        $status = new Status();
        $status->login($id, $username);
        session("user_info",
            [UserStatus::SESSION_ROLE => $role, UserStatus::SESSION_DEPARTMENT_ID => $departmentId]
            ,UserStatus::SESSION_PREFIX);
    }

    /**
     * @return mixed
     */
    public static function getUserInfo() {
        return session("user_info",'',UserStatus::SESSION_PREFIX);
    }

    public static function logout()
    {
        $status = new Status();
        $status->logout();
        session("user_info",null,UserStatus::SESSION_PREFIX);
    }


    public static function isLogin() {
        $status = new Status();
        return $status->isLogin();
    }
    public static function getLoginID() {
        $status = new Status();
        return $status->getLoginID();
    }
    public static function getDepartmentID() {
        return UserStatus::getUserInfo()[UserStatus::SESSION_DEPARTMENT_ID];
    }
    public static function getRole() {
        return UserStatus::getUserInfo()[UserStatus::SESSION_ROLE];
    }
}